package com.example.mentalhealth.Controller.AdminController;


import com.example.mentalhealth.Service.ExamPaperService;
import com.example.mentalhealth.Service.ExamRecordService;
import com.example.mentalhealth.Service.UserService;
import com.example.mentalhealth.entities.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

//管理首页api
@RestController
@RequestMapping("/api")
public class AdminDashboard {
    @Autowired
    private UserService userService;

    @Autowired
    private ExamPaperService examPaperService;


    @Autowired
    private ExamRecordService  examRecordService;

    /**
     * 获取统计数据
     * @return
     */
    @GetMapping("/getStatsData")
    public ResultData getStatsData(){
        UserStats userStats = new UserStats();
        //获取用户数量
        userStats.setUserCount(userService.queryUser().size());
        //获取试卷数量
        userStats.setExamCount(Math.toIntExact(examPaperService.queryExamPapersByPage(null, 1, 1000).getTotal()));
        //获取答卷数量
        userStats.setAnswerCount(examRecordService.queryAnswerCount());
        //获取今日答卷数量
        userStats.setTodayAnswerCount(examRecordService.queryTodayAnswerCount());
        return new ResultData(200,"success",userStats);
    }

    /**
     * 获取最近答卷数据
     * @return
     */
    @GetMapping("/getRecentAnswerData")
    public ResultData getRecentAnswerData(){
        List<ExamRecord> examRecordList = examRecordService.getRecentAnswerData();
        examRecordList.forEach(examRecord -> {
            examRecord.setTitle(examPaperService.getTitleById(examRecord.getPaperId()));
            examRecord.setUsername(userService.queryUserById(examRecord.getUserId()).getUsername());
        });

        return new ResultData(200,"success",examRecordList);
    }




}
